// fasttiming.cpp
//


#ifndef WIN32
#error This version of fasttiming is only valid on win32 platforms
#endif


// We want this to be compatible with MFC and non-MFC apps
#ifdef _AFXDLL
#include <afx.h>
#else
#include <windows.h>
#endif


#include "win32/fastTiming.h"


// Ruler
//       1         2         3         4         5         6    6
//345678901234567890123456789012345678901234567890123456789012345



// ************************
// *                      *
// *  apHiResElapsedTime  *
// *                      *
// ************************

apHiResElapsedTime::apHiResElapsedTime () : starting_ (0)
{
  reset ();
}


double apHiResElapsedTime::usec () const
{
  return sec() * 1000000.;
}

double apHiResElapsedTime::msec () const
{
  return sec() * 1000;
}

double apHiResElapsedTime::sec () const
{
  LARGE_INTEGER t, freq;
  QueryPerformanceCounter (&t);
  QueryPerformanceFrequency (&freq);

  return (double(t.QuadPart - starting_)) / freq.QuadPart;
}


void apHiResElapsedTime::reset ()
{
  LARGE_INTEGER t;
  QueryPerformanceCounter (&t);

  starting_ = t.QuadPart;
}
